#include "config.h"
Config config;
QString currentUser;
Config::Config()
{
    // 用户初始化
    User user("root", "123456");
    userList.push_back(user);
    User user2("dyx", "123456");
    userList.push_back(user2);
    // 菜品初始化
    dishList.push_back(Dish("bug大杂烩","程序员最讨厌的两件事：1.自己写文档\n2.别人不写文档","bugpaste.png",1145.14));
    dishList.push_back(Dish("乱炖java","java是世界上最好的语言！","javabest.png",66.66));
    dishList.push_back(Dish("炙烤c++","c++11，完美的配置！完美的崩溃！","barbecuecpp.png",66.66));
    // 订单初始化
    Order o =Order("bug大杂烩",2,"多来点bug");
    QVector<Order> v;
    v.push_back(o);
    Orderlist list = Orderlist("dyx", v);
    orderList.push_back(list);
}

Dish Config::queryDish(QString dishName)
{

    for (auto dish : dishList) {
        if (dish.dishName == dishName) return dish;
    }
}

bool Config::userNameExist(QString userName) {
    //用户名重复
    for (auto user : this->userList)
        if (user.user == userName) {
            return false;
        }
    //用户名合法
    return true;
}


bool Config::userNameCanChange(QString userName, QString oriName) {
    //用户名重复
    for (auto user : this->userList)
        if (user.user == userName && !(userName == oriName)) {
            return false;
        }
    //用户名合法
    return true;
}


bool Config::login(QString userName, QString password) {
    //检查用户名
    for (auto user : this->userList) {
        if (user.user == userName) {
            qDebug() << "【登录】用户名正确";
            if (user.pwd == password) {
                qDebug() << "【登录】密码正确";
                return true;
            }
            qDebug() << "【登录】密码错误";
            //登录失败
            return false;
        }
    }
    qDebug() << "【登录】用户名错误";
    //登录失败
    return false;
}
